<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title>商城后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/layui_ext/dtree/dtree.css}" >
    <link rel="stylesheet" th:href="@{/lib/layui_ext/dtree/font/dtreefont.css}" >
</head>
<body>

<span th:replace="common_page::common"></span>

<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" id="shopSearchForm" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">店铺ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">店铺名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">掌柜用户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userMainId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            <button type="reset" class="layui-btn layui-btn-primary" id="data-reset-btn" ><i class="layui-icon"></i> 重 置</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <span th:each="tb : ${toolbarButtons}" th:utext="${tb}"></span>

            </div>
        </script>

        <table class="layui-hide" id="shopTable" lay-filter="shopTableFilter"></table>

        <script type="text/html" id="shopTableBar">
            <span th:each="btn : ${rowButtons}" th:utext="${btn}"></span>
        </script>

    </div>
</div>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script>
    layui.config({
        base: basePath+'/lib/layui_ext/layarea/' //配置 layui 第三方扩展组件存放的基础目录
    }).extend({
        layarea: 'layarea' //定义该组件模块名
    }).use(['form', 'table','tree'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        var index;
        var loadding;

        $.fn.serializeJson=function(){
            var serializeObj={};
            var array=this.serializeArray();
            var str=this.serialize();
            $(array).each(function(){
                if(serializeObj[this.name]){
                    if($.isArray(serializeObj[this.name])){
                        serializeObj[this.name].push(this.value);
                    }else{
                        serializeObj[this.name]=[serializeObj[this.name],this.value];
                    }
                }else{
                    serializeObj[this.name]=this.value;
                }
            });
            return serializeObj;
        };

        function getFormParam()
        {
            var formParam = $("#shopSearchForm").serializeJson();
            return formParam;
        }

        table.render({
            elem: '#shopTable',
            url: "[[@{/}]]seller/shop/list",
            method:'POST',
            where:getFormParam(),
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter',  {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            done:function(res, curr, count)
            {
            },
            cols: [
                [
                    {type: "checkbox", width: 50},
                    {field: 'id',  title: '店铺ID'},
                    {field: 'publicShopId', width: 150, title: '公开店铺ID'},
                    {field: 'name',  width: 150, title: '店铺名称'},
                    {field: 'changeNameCount',  width: 120, title: '改名次数'},
                    {field: 'httpLogo', width: 150, title: '图标',
                        templet: function (row) {
                            if(row.httpLogo!=null) {
                                return "<a href='" + row.httpLogo + "' target='_blank'><img src='" + row.httpLogo + "' width='30' height='30'  /></a>";
                            }
                            return "";
                        }},
                    {field: 'introduce',  width: 150, title: '店铺介绍'},
                    {field: 'shopRank',  width: 150, title: '排名权重'},
                    {field: 'categoryMaxCount',  width: 150, title: '最大分类数量'},
                    {field: 'province',  width: 120, title: '省份'},
                    {field: 'provinceCode',  width: 120, title: '省份编码'},
                    {field: 'city',  width: 120, title: '市'},
                    {field: 'cityCode',  width: 120, title: '市编码'},
                    {field: 'area',  width: 120, title: '区县'},
                    {field: 'areaCode',  width: 120, title: '区县编码'},
                    {field: 'detailAddress',  width: 150, title: '详细地址'},
                    {field: 'userMainId',  width: 220,title: '所属掌柜用户ID'},
                    {field: 'enableStatus', width: 150, title: '启用状态',
                        templet: function (row) {
                            if(row.enableStatus == "0"){
                                return "禁用"
                            }
                            if(row.enableStatus == "1"){
                                return "启用"
                            }
                            return row.enableStatus;
                        }},
                    {field: 'type', width: 150, title: '类型',
                        templet: function (row) {
                            if(row.type == "1"){
                                return "个人"
                            }
                            if(row.type == "2"){
                                return "企业"
                            }
                            return row.type;
                        }},
                    {field: 'approveStatus', width: 150, title: '审核状态',
                        templet: function (row) {
                            if(row.approveStatus == "1"){
                                return "审核中"
                            }
                            if(row.approveStatus == "2"){
                                return "审核通过"
                            }
                            if(row.approveStatus == "3"){
                                return "审核驳回"
                            }
                            return row.approveStatus;
                        }},
                    {field: 'remark',  width: 200, title: '店铺备注'},
                    {field: 'createAdminName',width: 200, title: '创建人'},
                    {field: 'createDate', width: 200, title: '创建时间'},
                    {field: 'updateAdminName', width: 200, title: '修改人'},
                    {field: 'updateDate', width: 200, title: '修改时间'},
                    {title: '操作', minWidth: 300, toolbar: '#shopTableBar', align: "center"}
                ]
            ],
            limits: [15,30,100,200],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('shopTable', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });


        $("#data-reset-btn").click(function(){
            $("#shopSearchForm")[0].reset();
            layui.form.render();
        });

        function reloadTable(data)
        {
            //执行搜索重载
            table.reload('shopTable', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');
        }


        /**
         * toolbar监听事件
         */
        table.on('toolbar(shopTableFilter)', function (obj) {
            if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('shopTable')
                    , data = checkStatus.data;
                if(data==null||data.length<=0)
                {
                    layer.msg("请选择要操作的记录");
                    return;
                }
                layer.confirm('确定删除店铺?', function (index) {
                    $.ajax({
                        url:"[[@{/}]]seller/shop/delete/ids",
                        contentType: "application/json; charset=utf-8",
                        type:'DELETE',
                        data:JSON.stringify(data),
                        success:function(data){
                            layer.msg(data.msg);

                            //执行搜索重载
                            reloadTable(data);

                        },
                        complete:function(data)
                        {
                            layer.close(index);
                        }
                    });
                });
            }
        });


        //监听表格复选框选择
        table.on('checkbox(shopTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(shopTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event == 'disabledEnabledBtn') {
                var title="";
                if(data.enableStatus == "0"){
                    title= "启用";
                }
                if(data.enableStatus == "1"){
                    title = "禁用";
                }
                layer.confirm("确定"+title+"?", function (index) {
                    $.ajax({
                        url:"[[@{/}]]seller/shop/disabled/enabled/"+data.publicShopId,
                        contentType: "application/json; charset=utf-8",
                        type:'POST',
                        success:function(data){
                            layer.msg(data.msg);

                            //执行搜索重载
                            reloadTable(data);

                        },
                        complete:function(data)
                        {
                            layer.close(index);
                        }
                    });
                });
            }else if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑店铺',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    area: ['100%', '100%'],
                    content: '[[@{/}]]seller/shop/editPage/'+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if (obj.event === 'detail') {

                var index = layer.open({
                    title: '查看店铺',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,

                    area: ['100%', '100%'],
                    content: "[[@{/}]]seller/shop/detailPage/"+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if (obj.event === 'categoryList') {

                var index = layer.open({
                    title: '店铺分类列表',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,

                    area: ['100%', '100%'],
                    content: "[[@{/}]]seller/shop/category/listPage/"+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('确定删除该店铺?', function (index) {
                    $.ajax({
                        url:"[[@{/}]]seller/shop/delete/"+data.id,
                        contentType: "application/json; charset=utf-8",
                        type:'DELETE',
                        success:function(data){
                            layer.msg(data.msg);

                            //执行搜索重载
                            reloadTable(data);

                        },
                        complete:function(data)
                        {
                            layer.close(index);
                        }
                    });
                });
            }
        });

    });
</script>

</body>
</html>